package com.wyg.epdata.util.file;


import com.wyg.epdata.common.constant.BaseConstant;
import com.wyg.epcommonbase.common.util.CmdUtil;
import lombok.Data;
import lombok.SneakyThrows;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.Date;

/**
 * @Author: WangYongGan
 * @Date: 2021/11/8 20:50
 * @Description:
 */
@Data
public class HtmlTemplate {
    @Autowired
    SqlSessionFactory sqlSessionFactory;

    public void test() {
        final SqlSession sqlSession = sqlSessionFactory.openSession();
        sqlSession.getMapper(this.getClass());
    }

    @SneakyThrows
    public static String begin(String data1, String data2, String pdfPath) {
        String fileNamePrefix = String.valueOf(new Date().getTime());
        String htmlPath = BaseConstant.htmlDir + fileNamePrefix + ".html";
        FileUtil.saveFIle(BaseConstant.htmlBefore + "\n<!--more-->\n" + "data=" + data1 + "\ndata1=" + data2 + "\n<!--more-->\n" + BaseConstant.htmlAfter, htmlPath);
//        if(Constant.os.equals("linux"))
        htmlPath = BaseConstant.serverUrl + "/file/html/" + fileNamePrefix + ".html";
        String cmd = BaseConstant.cmdWk + htmlPath + " " + pdfPath;
        CmdUtil.doCmd(cmd);
        FileUtil.waitDownloadFile(pdfPath);

        Thread.sleep(1500);
//        FileUtil.deleteFile(htmlPath);
        return pdfPath;
    }


    public static void main(String[] args) {
        String path = "D:\\data\\java\\aa.pdf";
        System.out.println(ClassLoader.getSystemResource(""));
        String string = ClassLoader.getSystemResource("").toString();
        // split里面必须是正则表达式，"\\"的作用是对字符串转义*/
        System.out.println(path.contains("\\"));
        System.out.println(path);
        System.out.println(string.contains("/"));
        for (String s : string.split("/")) {
            System.out.println(s + "---");
        }
    }
}
